" Search the visual selection in visual mode
function! VSetSearchBoundedFunction()
  let s:temp =@@
  normal! gvy
  let @/ = '\V\<' . substitute(escape(@@, '\'), '\n', '\\n', 'g') . '\>'
  let @@ = s:temp
endfunction

function! VSetSearchBoundlessFunction()
  let s:temp =@@
  normal! gvy
  let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
  let @@ = s:temp
endfunction

xnoremap * :<c-u>call VSetSearchBoundedFunction()<cr>//<cr><c-o>
xnoremap # :<c-u>call VSetSearchBoundedFunction()<cr>??<cr><c-o>
xnoremap g* :<c-u>call VSetSearchBoundlessFunction()<cr>//<cr><c-o>
xnoremap g# :<c-u>call VSetSearchBoundlessFunction()<cr>??<cr><c-o>
